#include "master.h"

/* Video Variables */
/* specify SDL_NOFRAME for no frame :o */
int width = 800, height = 600, bpp = 32, vid_flags = SDL_OPENGL | SDL_HWSURFACE;

/* Base Program Variables */
bool running = true;
bool rendering_ortho = false;  
SDL_Event event;
GLfloat theta = 0.0f;
int screen_current = SCREEN_GAMEPLAY;

/* Input variables */
bool move_left = false;
bool move_right = false;
bool flip_brick = false;
bool move_down = false;

/* game variables */
int score;
int level;
bool game_over;

/* visual effects */
float score_glow = GLOW_MIN;

/* brick stuff */
bool new_brick = true;
int brick_x = 0;
int brick_y = 0;
float brick_move_timer = 0;
int brick_move_difficulty = 80; /* do not make over 99 */

/* shape types */
int brick_type_current = 0;
int brick_type_next = 0;
int brick_type_rotation = 0;
int brick_color_current = 4; /* 4-6 */
int brick_color_next = 5; /* 4-6 */

/* 10 across, 20 down */
int gameboard[GAMEBOARD_H][GAMEBOARD_W] = 
{
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {1, 1, 1, 1, 0, 0, 1, 3, 1, 1},
    {1, 1, 1, 1, 1,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0, 0, 0, 0, 1, 0, 2, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0},
    {0, 0, 4, 0, 0, 0, 4, 0, 0, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0},
    {0, 2, 2, 0, 3, 0, 4, 4, 0, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 4, 4, 0, 0, 3, 2, 0, 0, 0, 0},
    {2, 2, 3, 3, 3, 0, 4, 0, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 4, 4, 2, 0, 3, 2, 2, 2, 2, 2},
    {4, 4, 4, 4, 2, 3, 3, 2, 2, 2, 4, 4, 2, 2, 2, 2, 3, 3, 2, 2, 4, 4, 2, 2, 2, 3, 2, 3, 3, 2, 2, 2, 2, 2}
};


/* T Shaped Brick */
int brick_T[GAMEPIECE_ROTATIONS][GAMEPIECE_H][GAMEPIECE_W] =
{
    {
        {0, 1, 0, 0},
        {0, 1, 1, 0},
        {0, 1, 0, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {1, 1, 1, 0},
        {0, 1, 0, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 1, 0, 0},
        {1, 1, 0, 0},
        {0, 1, 0, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 1, 0, 0},
        {1, 1, 1, 0},
        {0, 0, 0, 0},
        {0, 0, 0, 0}
    }
};

/* I Shaped Brick */
int brick_I[GAMEPIECE_ROTATIONS][GAMEPIECE_H][GAMEPIECE_W] =
{
    {
        {0, 1, 0, 0},
        {0, 1, 0, 0},
        {0, 1, 0, 0},
        {0, 1, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {1, 1, 1, 1},
        {0, 0, 0, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 1, 0, 0},
        {0, 1, 0, 0},
        {0, 1, 0, 0},
        {0, 1, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {1, 1, 1, 1},
        {0, 0, 0, 0},
        {0, 0, 0, 0}
    }
};


/* J Shaped Brick */
int brick_J[GAMEPIECE_ROTATIONS][GAMEPIECE_H][GAMEPIECE_W] =
{
    {
        {0, 1, 0, 0},
        {0, 1, 0, 0},
        {0, 1, 1, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {0, 1, 1, 1},
        {0, 1, 0, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {0, 1, 1, 0},
        {0, 0, 1, 0},
        {0, 0, 1, 0}
    },
    {
        {0, 0, 0, 0},
        {0, 0, 1, 0},
        {1, 1, 1, 0},
        {0, 0, 0, 0}
    }
};


/* L Shaped Brick */
int brick_L[GAMEPIECE_ROTATIONS][GAMEPIECE_H][GAMEPIECE_W] =
{
    {
        {0, 0, 0, 0},
        {0, 1, 1, 0},
        {0, 1, 0, 0},
        {0, 1, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {1, 1, 1, 0},
        {0, 0, 1, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 0, 1, 0},
        {0, 0, 1, 0},
        {0, 1, 1, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {0, 1, 0, 0},
        {0, 1, 1, 1},
        {0, 0, 0, 0}
    }
};


/* O Shaped Brick */
int brick_O[GAMEPIECE_ROTATIONS][GAMEPIECE_H][GAMEPIECE_W] =
{
    {
        {0, 0, 0, 0},
        {0, 1, 1, 0},
        {0, 1, 1, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {0, 1, 1, 0},
        {0, 1, 1, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {0, 1, 1, 0},
        {0, 1, 1, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {0, 1, 1, 0},
        {0, 1, 1, 0},
        {0, 0, 0, 0}
    }
};


/* Z Shaped Brick */
int brick_Z[GAMEPIECE_ROTATIONS][GAMEPIECE_H][GAMEPIECE_W] =
{
    {
        {0, 0, 0, 0},
        {0, 0, 1, 0},
        {0, 1, 1, 0},
        {0, 1, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {1, 1, 0, 0},
        {0, 1, 1, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {0, 0, 1, 0},
        {0, 1, 1, 0},
        {0, 1, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {1, 1, 0, 0},
        {0, 1, 1, 0},
        {0, 0, 0, 0}
    }
};

/* S Shaped Brick */
int brick_S[GAMEPIECE_ROTATIONS][GAMEPIECE_H][GAMEPIECE_W] =
{
    {
        {0, 1, 0, 0},
        {0, 1, 1, 0},
        {0, 0, 1, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {0, 1, 1, 0},
        {1, 1, 0, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 1, 0, 0},
        {0, 1, 1, 0},
        {0, 0, 1, 0},
        {0, 0, 0, 0}
    },
    {
        {0, 0, 0, 0},
        {0, 1, 1, 0},
        {1, 1, 0, 0},
        {0, 0, 0, 0}
    }
};
